<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>axios发送ajax请求</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
  <button>GET</button>
  <button>POST</button>
  <button>AJAX</button>
  <script>
    var btn = document.querySelectorAll('button');
    btn[0].onclick = function () {
        //get请求
      axios.get('http://localhost:8000/axios-server',{
        //参数
        params: {
          name:'cty',
          age:'21'
        },
        //头信息
        headers: {
            name:'cty'
        },
      }).then(data => (
          console.log(data)
          )
      )//返回结果
    }
    //post请求
    btn[1].onclick = function () {
        axios.post('http://localhost:8000/axios-server'/*url*/,{'name':'cty','age':'18'}/*请求体*/
            ,/*其他的参数*/{
                params: {
                    name:'cty',
                    age:'18'
                },
                headers: {
                    name:'beauty'
                }
            }
        )
    }
    //axios请求
    btn[2].onclick =function () {
        axios( {
            //请求方式
            method:'post',
            //URL
            url:'http://localhost:8000/axios-server',
            //请求头
            headers: {
                age:'18',
                name:'cty'
            },
            //请求体
            data: {
                age:'18',
                name:'cty'
            }
        }).then(response => {//回调
            console.log(response)
        })
    }
  </script>

</body>
</html>